import {request} from 'umi';
import {encrypt} from "@/utils/encrypt";
const PROJECT_NAME = process.env.PROJECT_NAME;


/**
 * 分页列表
 * @param param
 */
export async function findPage(data: any) {
  return request(`/${PROJECT_NAME}/sys/sysuser/findPage`, {method: 'POST', data});
}

/**
 * 新增
 * @param data
 * @returns
 */
export async function addNewUser(data: any) {
  return request(`/${PROJECT_NAME}/sys/sysuser/addNewUser`, {method: 'POST', data});
}

/**
 * 修改
 * @param data
 * @returns
 */
export async function updateObject(data: any) {
  return request(`/${PROJECT_NAME}/sys/sysuser/updateObject`, {method: 'POST', data});
}

/**
 * 删除
 * @param param
 */
export async function fakeDelete(data: any) {
  return request(`/${PROJECT_NAME}/sys/sysuser/fakeDelete`, {method: 'POST', data});
}

/**
 * 菜单获取
 * @param param
 */
export async function getLoginUserMenu(data: any) {
  return request(`/${PROJECT_NAME}/sys/sysuser/getLoginUserMenu`, {method: 'POST', data});
}

/**
 * 修改密码
 * @param data
 * @returns
 */
export async function updatePwd(data: any) {
  // 首先获取公钥
  const result = await request(`/${PROJECT_NAME}/getPublicKey`, { method: 'POST' });
  const publicKey = result.msg;
  const enData = encrypt(JSON.stringify(data), publicKey);
  const params = {
    jsonData: enData,
    publicKey
  };
  return request(`/${PROJECT_NAME}/sys/sysuser/updatePwd_encrypted`, {method: 'POST', data: params});
}

/**
 * 启用停用
 * @param data
 * @returns
 */
export async function updateStatus(data: any) {
  return request(`/${PROJECT_NAME}/sys/sysuser/updateStatus`, {method: 'POST', data});
}

/**
 * 解锁
 * @param data
 * @returns
 */
export async function unlockUser(data: any) {
  return request(`/${PROJECT_NAME}/sys/sysuser/unlockUser`, {method: 'POST', data});
}

